﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using WebApiClient;

namespace ARchGL.Platform.FileServer
{
    /// <summary>
    /// 文件服务 接口
    /// </summary>
    public static class FileServerHttpsModule
    {
        public static IServiceCollection Register(IServiceCollection services, IConfigurationRoot appConfiguration)
        {
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            void config(HttpApiConfig c)
            {
                c.HttpHost = new Uri(appConfiguration["Authentication:SpiderConfigOptions:TokenUrl"]); //文件服务
                c.GlobalFilters.Add(new DefaultHeaderAttribute(appConfiguration));
                //c.GlobalFilters.Add(new ServiceTokenAttribute());
            }

            services.AddHttpApi<IFileServerApi>().ConfigureHttpApiConfig(config); //注入接口

            return services;
        }
    }
}
